<template>
  <div class="oe-major-class" v-loading="loading">
    <info-top @toggleCollapsed="toggleCollapsed"></info-top>
    <div class="oe-major-list">
      <div class="oe-major-lis" v-for="(item, index) in list" :key="index" @click="getSortId(item)">
        <p class="oe-major-title">
          <i
            class="iconfont icon-zhuanye"
            style="font-size: 34px;vertical-align: -5px;color:#1E8DFD;margin-right:10px;"
          ></i>
          {{ item.Title }}
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import infoTop from '@/components/info-top/index.vue';
export default {
  components: {
    infoTop
  },
  data() {
    return {
      list: [],
      loading: false,
      isHasBatch: true
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.$http.post('/api/study/sort/getList').then((res) => {
        this.loading = false;
        if (res.list.length > 0) {
          this.list = res.list;
          this.isHasBatch = res.isHasBatch;
        } else {
          this.$router.push({
            name: 'batchList'
          });
        }
      });
    },
    getSortId(item) {
      localStorage.setItem('sortId', item.Id);
      localStorage.setItem('sortItem', JSON.stringify(item));
      if (this.isHasBatch) {
        this.$router.push({
          name: 'batchList'
        });
      } else {
        this.getBacthList();
      }
    },
    // 批次列表
    getBacthList() {
      this.$http
        .post('/api/study/batch/getList', {
          title: '',
          type: 1
        })
        .then((rst) => {
          if (rst.code > 0) {
              localStorage.setItem('bacthId', rst.list[0].Id);
          } else {
            this.$message.error(rst.msg);
          };
          this.$router.push({
            name: 'current'
          });
        });
    },
  }
};
</script>

<style></style>
